
# 需要将数字格式化后输出,并控制数字的位数,对齐,千位分隔符和其他的细节
# 指定宽度和精度的一般形式是 [<>^]?width[,]?(.digits)?   其中width和digits为整数,?代表可选部分
def demo_1():
    x = 1234.5678
    print(format(x, '0.2f'))
    # 打印结果右移10个字符
    print(format(x, '>10.1f'))
    print(format(x, '<10.1f'))
    print(format(x, '^10.1f'))
    print(format(x, ','))
    print(format(x, '0,.1f'))
    print(format(x, 'e'))
    print(format(x, '0.2E'))
    print(format('The value is {:0,.2f}'.format(x)))

def demo_2():
    x = 1234.56789
    swap_separators = {ord('.'):',', ord(','):'.'}
    print(format(x, ',').translate(swap_separators))

if __name__ == '__main__':
    # demo_1()
    demo_2()